import {Falsey, compact, isArray, isEmpty, isNil, isObject, omitBy} from 'lodash';

export function filterEmpty<T>(data: Array<T | Falsey>): T[];
export function filterEmpty<T>(data: {[k: string]: T | Falsey}): {[k: string]: T};

export function filterEmpty<T>(data: T) {
    if (isArray(data)) {
        return compact(data);
    }
    if (isObject(data)) {
        return omitBy(data, value => isNil(value) || isEmpty(value));
    }
    return Array.isArray(data) ? data : [data];
}
